package com.iweb.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "DoReg", urlPatterns = {"/servlet/DoReg"})
public class DoReg extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String path = req.getContextPath();
        Integer pwdLength = password.length();
        if (username != null && "admin".equals(username)!=true && password != null && pwdLength >= 6) {
            req.setAttribute("username",username);
            req.getRequestDispatcher("/day04/admin.jsp").forward(req, resp);
        } else {
            resp.sendRedirect(path + "/day04/reg.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        this.doGet(req, resp);
    }
}
